import { createSlice } from '@reduxjs/toolkit'

export const authSlice=createSlice({
    name:'auth',
    initialState:{
        token:sessionStorage.getItem('token') || null,
        menuList:[]
    },
    reducers:{
        setToken:(state,action)=>{
            state.token = action.payload
            sessionStorage.setItem('token',action.payload)
        },
        clearToken:state=>{
            state.token = null;
            sessionStorage.removeItem('token')
        },
        setMenuList:(state,action)=>{
            state.menuList = action.payload
        }
    }
})

export const {setToken,clearToken,setMenuList}=authSlice.actions

export default authSlice.reducer